//
//  YQFourTypeBtnView.m
//  OverseasImmigration
//
//  Created by yuqin on 2019/6/2.
//  Copyright © 2019年 yuqin. All rights reserved.
//

#import "YQFourTypeBtnView.h"

@implementation YQFourTypeBtnView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView {
    NSArray *titleArr = @[@"海外房产",@"移民项目",@"大国签证",@"移民攻略"];
    NSArray *imgArr = @[@"estate",@"Project",@"visacopyx",@"bookmark"];
    CGFloat btnWidth = SCREENWIDTH/4.0;
    CGFloat img_X = btnWidth/2.0-15;

    for (NSInteger i = 0; i<4; i++) {
//        UIImageView *img = [[UIImageView alloc] init];
//        img.image = YQImg(imgArr[i]);
//        img.tag = 100+i;
//        [self addSubview:img];
//        img.frame = CGRectMake(img_X+btnWidth*i, 10, 30, 30);
//        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchAction:)];
//        [img addGestureRecognizer:tap];
//        img.userInteractionEnabled = YES;
        UIButton *imgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [imgBtn setImage:YQImg(imgArr[i]) forState:UIControlStateNormal];
        imgBtn.tag = 10+i;
        [self addSubview:imgBtn];
        imgBtn.frame = CGRectMake(img_X+btnWidth*i, 10, 30, 30);
        [imgBtn addTarget:self action:@selector(selectedAction:) forControlEvents:UIControlEventTouchUpInside];
        
        
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:titleArr[i] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        btn.titleLabel.textAlignment = NSTextAlignmentCenter;
        btn.tag = 10+i;
        btn.titleLabel.font = YQFont(14);
        [self addSubview:btn];
        [btn addTarget:self action:@selector(selectedAction:) forControlEvents:UIControlEventTouchUpInside];
        btn.frame = CGRectMake(btnWidth*i, 50, btnWidth, 20);
    }
}

- (void)selectedAction:(UIButton *)btn {
    if (self.block) {
        self.block(btn.tag-9);
    }

}



@end
